package es.abredatos.server;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Tutorial {

	@Override
	public String toString() {
		return "Tutorial [autor=" + autor + ", fecha=" + fecha + ", id=" + id + ", tutorial=" + tutorial + "]";
	}

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private String autor;

	@Persistent
	private String tutorial;

	@Persistent
	private Date fecha;

	private static SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

	public Tutorial(final String autor, final String tutorial) {
		this.autor = autor;
		this.tutorial = tutorial;
		this.fecha = new Date();
	}

	public String getAutor() {
		return autor;
	}

	public String getTutorial() {
		return tutorial;
	}

	public Date getFecha() {
		return fecha;
	}

	public String getFechaFormatted() {
		return formatter.format(fecha);
	}
}
